    var _planId ="";
	var _pushId="";
	var playTime=10;
	var res = [];
	var timer = null;
	var num =0;
	var supervisePlayer =null;
	var session =null;
	$(function() {
		showToolsBar();
		$.ajax({
			 url:"/h5streamapi/login",
			 type:"get",
			 timeout: 5000,
			 success:function(data){
				 session = data;
			 }
		 });
		var webSocket1 = new KDWebSocket("/sockjs/supervisePlan", {
			onmsg : function(data) {
				$("#my-supervise-plan-datagrid").datagrid("reload");
			}
		});
		webSocket1.run();
	});
	
	 
	
	function previewPlan(planId, pushId,splayTime) {
		num=0;
		if(timer){
			clearInterval(timer);
			$("#planInfo").html("");
			$("#planInfo").addClass("hidden");
		}
		layer.confirm('是否执行此操作？', {
			icon : 3,
			btn : [ '确认', '取消' ]
		}, function(index) {
			layer.close(index);
			_planId =planId;
			_pushId =pushId
			if(splayTime){
			    playTime =parseInt(splayTime, 10);
			}
			beginPreview(playTime, planId,pushId);
		}, function(index) {
			layer.close(index);
		});
	}
	
	function beginPreview(playTime, planId,pushId){
		var resources= getResource(planId);
		var length = resources.length;
		if(length>0){
			writeAddressAndPlay(planId, pushId,resources[num].resourceUuid);
			timer = setInterval(function() {
				num++;
				if (num >= length) {//预览结束
					//清除定时器
					clear();
					$.ajax({
			    		url:"/video/plan/"+pushId+"/updateRecord",
			    		type:"POST",
			    	});
					refreshDataGrid();
				}else{
					$("#planInfo").text("正在播放："+resources[num].resourceName);
					writeAddressAndPlay(planId, pushId,resources[num].resourceUuid);
				}
			}, playTime * 1000);
		}
	}
	function clear(){
		if(timer){
			clearInterval(timer);
			if(supervisePlayer){
				supervisePlayer.reset()
			}
		}
		
	}
	
	function getResource(planId){
		$.ajax({
			url:"/video/plan/res/"+planId+"/getResources",
			type:'post',
			async:false,
			success:function(data){
				res = JSON.parse(data);
			}
		});
		return res;
	}
	function stop(){
		var planId = _planId
		var pushId = _pushId
		layer.confirm('是否执行此操作？', {
			icon : 3,
			btn : [ '确认', '取消' ]
		}, function(index) {
			layer.close(index);
			if(timer){
				clearInterval(timer);
			 
			}
		  	if(supervisePlayer){
				supervisePlayer.reset()
			}
			$.ajax({
	    		url:"/video/plan/"+pushId+"/updateRecord",
	    		type:"POST",
	    		success:function(data){
	    			refreshDataGrid();
	    		}
	    	});
			layer.confirm('是否要上报情况？', {
				icon : 3,
				btn : [ '确认', '取消' ]
			}, function(index) {
				layer.close(index);
				var url = "/video/plan/log/"+planId+"/"+pushId+"/add";
			   	var _customerClass = ($(this).attr("customer-id") == undefined) ? "customer-id": $(this).attr("customer-id");
				$("<div/>").addClass("customer-dialog " + _customerClass).window({
					width : "96%" ,
					height : "96%",
					modal : true,
					minimizable : false,
					resizable : false,
					title : "<i class=\"iconfont icon-windows\"></i>" + "情况上报",
					border : false,
					onClose : function() {
						$(this).window('destroy');
					},
					href : url
				});
			}, function(index) {
				layer.close(index);
			});
		}, function(index) {
			layer.close(index);
			 
		});
	}
	function pause(){
	    if(timer){
			clearInterval(timer);
		}
    }
   function play(){
	 	var planId = _planId
		var pushId = _pushId
	  	beginPreview(playTime, planId,pushId);
   }
   
   function openRecordWin(obj){
   	var planId = _planId
   	var pushId = _pushId
   	//弹出日志窗口
   	var url = "/video/plan/log/"+planId+"/"+pushId+"/add";
   	var titleName = $(obj).attr("title");
    var _width = ($(obj).attr("data-win-width") == undefined) ? "96%" : $(obj).attr("data-win-width");
   	var _height = ($(obj).attr("data-win-height") == undefined) ? "96%" : $(obj).attr("data-win-height");
   	var _customerClass = ($(obj).attr("customer-id") == undefined) ? "customer-id": $(obj).attr("customer-id");
	$("<div/>").addClass("customer-dialog " + _customerClass).window({
		width : _width,
		height : _height,
		modal : true,
		minimizable : false,
		resizable : false,
		title : "<i class=\"iconfont icon-windows\"></i>" + titleName,
		border : false,
		onClose : function() {
			$(this).window('destroy');
		},
		href : url
	});
	return false;
   }